package cn.i5.remoteinvocationcontrol.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mc0710
 */
public class CommonUtils {

    /**
     * 获取IP
     *
     * @param request req
     * @return ip
     */
    public static String getIp(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("x-real-ip");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

}
